{extend name="platform/base" /}
{block name="resources"/}
<style type="text/css">
.required{
	color:red;margin-right:10px;
}
</style>
{/block}
{block name="main"}
<section class="panel panel-default">
	<header class="panel-heading font-bold"> 修改文章</header>
	<div class="panel-body">
		<form class="form-horizontal" id="form" name="form" onsubmit="">
		   <input type="hidden" value="{$article_id}" id="article_id"/>
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="required">*</span>文章标题</label>
				<div class="col-md-6">
					<input type="text" class="form-control" id="title" value="{$ArticleDetail.title}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">文章短标题</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="short_title" value="{$ArticleDetail.short_title}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">文章标签</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="tag"   value="{$ArticleDetail.tag}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<!-- 上传图片 -->
			<div class="form-group">
                                   <label class="col-sm-2 control-label">标题图片</label>
                                   <div class="col-sm-4">
                                   	<p>
                                   	       {if condition="$ArticleDetail.image eq ''"} 
										    	<img id="imgLogo" src=""> 
											{else/}
							 				    <img id="imgLogo" src="__ROOT__/{$ArticleDetail.image}"> 
											{/if} 
                                   	
                                   	<a href="javascript:void(0);" style="display:block;position:relative;z-index:1;">
                                   		<span style="width: 97px;height: 34px;position: absolute;left: 0;top: 0;z-index: 2;cursor: pointer;"> 
                                   		<input hidefocus="true" size="1" class="input-file" name="file_upload"
					id="uploadImg" nc_type="change_store_label" type="file" style="width: 97px;height: 34px;padding: 0;margin: 0;border: none 0;opacity: 0;filter: alpha(opacity = 0);cursor: pointer;"
					onchange="imgUpload(this);"> 
					<input type="hidden" id="Logo" value="{$ArticleDetail.image}" />
				</span>
				<a class="btn btn-default"><i class="fa fa-cloud-upload text"></i><span class="text">上传图片</span></a>
		            	</a>
                                   </div>
            </div>
		
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">文章作者</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="author" value="{$ArticleDetail.author}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label">文章来源</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="source"   value="{$ArticleDetail.source}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label">文章来源链接</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="url" value="{$ArticleDetail.url}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label"><span class="required">*</span>所属分类</label>
				<div class="col-sm-4">
					<select id="class_id" name="account" class="form-control m-b">
						<option value="0">请选择</option> 
						 {volist name="articleClassList['data']" id="vo"}
						 {if condition="$vo.pid eq 0"}
						<option value="{$vo.pid}" disabled="disabled">{$vo.name}</option>
						 {/if} 
						 {volist name="articleClassList['data']" id="v2"}
							 {if condition="$vo.class_id eq $v2.pid"}
							<option value="{$v2.class_id}" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$v2.name}</option>
						    {/if} 
					    {/volist} {/volist}   
					    
					</select>
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
				<label class="col-sm-2 control-label">文章关键字</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="keyword" value="{$ArticleDetail.keyword}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			<div class="form-group">
                <label class="col-sm-2 control-label">文章摘要</label>
               <textarea id="summary"  cols="10" rows="10" class="form-control" style="width:755px;height:150px;margin-left:210px;">{$ArticleDetail.summary}</textarea>
                </div>
			<!-- 书签 -->
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label"><span class="required">*</span>文章内容</label>
				      <div class="col-sm-8">
	                         <div class="btn-toolbar m-b-sm btn-editor" data-role="editor-toolbar" data-target="#editor">
	                             <div class="btn-group"> <a class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" title="Font"><i class="fa fa-font"></i><b class="caret"></b></a>
	                                 <ul class="dropdown-menu">
	                                 </ul>
	                             </div>
	                             <div class="btn-group"> <a class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" title="Font Size"><i class="fa fa-text-height"></i>&nbsp;<b class="caret"></b></a>
	                                 <ul class="dropdown-menu">
	                                     <li>
	                                         <a data-edit="fontSize 5">
	                                             <font size="5">Huge</font>
	                                         </a>
	                                     </li>
	                                     <li>
	                                         <a data-edit="fontSize 3">
	                                             <font size="3">Normal</font>
	                                         </a>
	                                     </li>
	                                     <li>
	                                         <a data-edit="fontSize 1">
	                                             <font size="1">Small</font>
	                                         </a>
	                                     </li>
	                                 </ul>
	                             </div>
	                             <div class="btn-group"> <a class="btn btn-default btn-sm" data-edit="bold" title="Bold (Ctrl/Cmd+B)"><i class="fa fa-bold"></i></a> <a class="btn btn-default btn-sm" data-edit="italic" title="Italic (Ctrl/Cmd+I)"><i class="fa fa-italic"></i></a> <a class="btn btn-default btn-sm" data-edit="strikethrough" title="Strikethrough"><i class="fa fa-strikethrough"></i></a> <a class="btn btn-default btn-sm" data-edit="underline" title="Underline (Ctrl/Cmd+U)"><i class="fa fa-underline"></i></a> </div>
	                             <div class="btn-group"> <a class="btn btn-default btn-sm" data-edit="insertunorderedlist" title="Bullet list"><i class="fa fa-list-ul"></i></a> <a class="btn btn-default btn-sm" data-edit="insertorderedlist" title="Number list"><i class="fa fa-list-ol"></i></a> <a class="btn btn-default btn-sm" data-edit="outdent" title="Reduce indent (Shift+Tab)"><i class="fa fa-dedent"></i></a> <a class="btn btn-default btn-sm" data-edit="indent" title="Indent (Tab)"><i class="fa fa-indent"></i></a> </div>
	                             <div class="btn-group"> <a class="btn btn-default btn-sm" data-edit="justifyleft" title="Align Left (Ctrl/Cmd+L)"><i class="fa fa-align-left"></i></a> <a class="btn btn-default btn-sm" data-edit="justifycenter" title="Center (Ctrl/Cmd+E)"><i class="fa fa-align-center"></i></a> <a class="btn btn-default btn-sm" data-edit="justifyright" title="Align Right (Ctrl/Cmd+R)"><i class="fa fa-align-right"></i></a> <a class="btn btn-default btn-sm" data-edit="justifyfull" title="Justify (Ctrl/Cmd+J)"><i class="fa fa-align-justify"></i></a> </div>
	                             <div class="btn-group"> <a class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" title="Hyperlink"><i class="fa fa-link"></i></a>
	                                 <div class="dropdown-menu">
	                                     <div class="input-group m-l-xs m-r-xs">
	                                         <input class="form-control input-sm" placeholder="URL" type="text" data-edit="createLink">
	                                         <div class="input-group-btn">
	                                             <button class="btn btn-default btn-sm" type="button">Add</button>
	                                         </div>
	                                     </div>
	                                 </div>
	                                 <a class="btn btn-default btn-sm" data-edit="unlink" title="Remove Hyperlink"><i class="fa fa-cut"></i></a> </div>
	                             <div class="btn-group"> <a class="btn btn-default btn-sm" title="Insert picture (or just drag & drop)" id="pictureBtn"><i class="fa fa-picture-o"></i></a>
	                                 <input type="file" data-role="magic-overlay" data-target="#pictureBtn" data-edit="insertImage" />
	                             </div>
	                             <div class="btn-group"> <a class="btn btn-default btn-sm" data-edit="undo" title="Undo (Ctrl/Cmd+Z)"><i class="fa fa-undo"></i></a> <a class="btn btn-default btn-sm" data-edit="redo" title="Redo (Ctrl/Cmd+Y)"><i class="fa fa-repeat"></i></a> </div>
	                             <input type="text" class="form-control-trans pull-left" data-edit="inserttext" id="voiceBtn" x-webkit-speech="" style="width:25px;height:28px;">
	                         </div>
	                         <div id="editor" class="form-control" style="overflow:scroll;height:150px;max-height:150px">{$ArticleDetail.content}</div>
	                     </div>
			    </div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label">文章附件</label>
				    <div id='upload_file'>
					<div>
		                <input class="input-file" type="file" name="file_upload" id="file_upload_input" onchange="FileUpload(this)" style="margin-left:210px;">
		                <div class='files' style="margin-left:210px;width:250px;">
		                 {foreach name="attachment_path" item="vo"}
				            {if condition="$vo neq ''"}
							    <p><span>{$vo}</span><a href="javascript:;" onclick="delete_file('{$vo}',this)">删除</a></p>
							{/if}
						 {/foreach}
		                </div>
		            </div>
		            </div>
			    </div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label">相关文章</label>
				<div class="col-md-4">
					<input type="text" class="form-control" id="article_id_array"   value="{$ArticleDetail.article_id_array}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
					<label class="col-sm-2 control-label">推荐</label>
					 <div style="margin-top:5px;float:left;margin-left:15px;">
					  {if condition='$ArticleDetail.commend_flag eq 1'}
					     <input type="checkbox" value="" id="commend_flag" checked="checked"/>
				         {else /} <input type="checkbox" value="" id="commend_flag"/>
				       {/if}   
			         </div>
					<label class="col-sm-2 control-label">允许评论</label>
					<div style="margin-top:5px;float:left;">
					   {if condition='$ArticleDetail.comment_flag eq 1'}
	                    <input type="checkbox" value="" id="comment_flag" checked="checked"/>
				        {else /} <input type="checkbox" value="" id="comment_flag"/>
				        {/if}  
			        </div>
		       </div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label">文章排序</label>
				<div class="col-md-1">
					<input type="text" class="form-control" id="sort"  value="{$ArticleDetail.sort}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label">文章点击量</label>
				<div class="col-md-1">
					<input type="text" class="form-control" id="click" value="{$ArticleDetail.click}" >
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label">文章评论数</label>
				<div class="col-md-1">
					<input type="text" class="form-control" id="comment_count" value="{$ArticleDetail.comment_count}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
				<div class="form-group">
				<label class="col-sm-2 control-label">文章分享数</label>
				<div class="col-md-1">
					<input type="text" class="form-control" id="share_count" value="{$ArticleDetail.share_count}">
				</div>
			</div>
			<div class="line line-dashed line-lg pull-in"></div>
			
			
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<a href="javascript:void(0);" onclick="save(1)" class="btn btn-primary">修改文章</a>
					<a href="javascript:void(0);" onclick="save(2)" class="btn btn-primary">修改并预览</a>
				</div>
			</div>
		</form>
	</div>
</section>
   
{/block} 
{block name="script"}
<script src="PLATFORM_JS/ajaxFileUpload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
{include file="platform/openDialog" /}
  <script type="text/javascript">
  window.onload=function(){
	  $("#class_id").val({$ArticleDetail.class_id});
  }
     function save(type){
    	 var comment_flag=$('#comment_flag').is(':checked')?'1':'0';
    	 var commend_flag=$('#commend_flag').is(':checked')?'1':'0';
         var article_id=$("#article_id").val();
    	 var title=$("#title").val();
    	 var class_id=$("#class_id").val();
    	 var short_title=$("#short_title").val();
    	 var source=$("#source").val();
    	 var url=$("#url").val();
    	 var author=$("#author").val();
    	 var summary=$("#summary").val();
    	 var content=$("#editor").text();
    	 var image=$("#Logo").val();
    	 var keyword=$("#keyword").val();
    	 var article_id_array=$("#article_id_array").val();
    	 var click=$("#click").val();
    	 var sort=$("#sort").val();
    	 var tag=$("#tag").val();
    	 var comment_count=$("#comment_count").val();
    	 var share_count=$("#share_count").val();
    	 var attachment_path='';
    	 $('.files>p>span').each(function(){
    		 attachment_path+=$(this).text()+',';
    	 })
    	 attachment_path=attachment_path.substring(0,attachment_path.length-1);
     	 if(title==''){
    		 $("#title").focus();
    		 return false;
    	 }
    	 if(class_id==0){
    		 $("#class_id").focus();
    		 return false;
    	 }
    	 if(content==null || content.length==0){
    		 $("#editor").focus();
    		 return false;
    	 }
    	$.ajax({
    		type:"post",
    	    url:"PLATFORM_MAIN/Cms/ajax_updateArticle",
    	    data:{
    	      'article_id':article_id,
    	      'title':title,   
    	      'class_id':class_id,
    	      'short_title':short_title,
    	      'source':source,
    	      'url':url,
    	      'author':author,
    	      'summary':summary,
    	      'content':content,
    	      'image':image,
    	      'keyword':keyword,
    	      'article_id_array':article_id_array,
    	      'click':click,
    	      'sort':sort,
    	      'commend_flag':commend_flag,
    	      'comment_flag':comment_flag,
    	      'attachment_path':attachment_path,
    	      'tag':tag,
    	      'comment_count':comment_count,
    	      'share_count':share_count
    	     
    	},
    	    async : true,
    	    success:function(data){
    			   //alert(JSON.stringify(data)); 
    	    		if (data["code"] > 0) {
    						showMessage('success', data["message"]);
    						if(type==2 && article_id>0){
    							window.open("SHOP_MAIN/Cms/articleClassInfo?article_id="+article_id);
    						}else if(type==1){
    							location.href="PLATFORM_MAIN/Cms/articleList";	
    						}
    						
    					}else{
    						showMessage('error', data["message"]);
    					}
    	    }
    	
    	});
    	 
    	 
     }
     /**
 	 *图片上传
 	 */
 	function imgUpload(event) {
 		var fileid = $(event).attr("id");
 		var data = { 'file_path' : UPLOADCOMMON };
 		uploadFile(fileid,data,function(res){
 			if(res.code){
 				$("#imgLogo").attr("src","__UPLOAD__/"+res.data);
 				$("#Logo").val(res.data);
 				showTip(res.message,"success");
 			}else{
 				showTip(res.message,"error");
 			}
 		});
 	}
//  	function imgUpload(event) {
//  		var fileid = $(event).attr("id");   var str = $(event).next().attr("id");
//  		fileCommonUpload("UPLOAD_URL", fileid,"__UPLOAD__",str);
//  	}
  	/**
	*上传附件
	*/
	function FileUpload(event) {
		var fileid = "file_upload_input";
		if($('#'+fileid).val()==''){
			$( "#dialog" ).dialog({
				            buttons: {
				                "确定,#e57373": function() {
				                    $(this).dialog('close');
				                }
				            },
				            contentText:"请选择附件"
				        });
		}else{
			$.ajaxFileUpload({
				url : 'PLATFORM_MAIN/System/File_Upload', //用于文件上传的服务器端请求地址
				secureuri : false, //一般设置为false
				fileElementId : fileid, //文件上传空间的id属性  <input type="file" id="file" name="file" />
				dataType : 'text', //返回值类型 一般设置为json
				async : false,
				data:{'Enclosure':1},
				contentType : "text/json;charset=utf-8",
				success : function(data) //服务器成功响应处理函数
				{
					if (data) {
						$( "#dialog" ).dialog({
				            buttons: {
				                "确定,#01B044": function() {
				                    $(this).dialog('close');
				                }
				            },
				            contentText:"附件上传成功",
				      		time:1,
				        });
						$('.files').append('<p><span>'+data+'</span><a href="javascript:;" onclick="delete_file(\''+data+'\',this)">删除</a></p>');
					}else{
						$( "#dialog" ).dialog({
				            buttons: {
				                "确定,#e57373": function() {
				                    $(this).dialog('close');
				                }
				            },
				            contentText:"附件上传失败"
				        });
					}
				}
			});
		}
	
	}
	/**
	 * 删除文件
	 * @param {Object} file_url
	 * @param {Object} even
	 */
 	function delete_file(file_url,even){
 	
 		$.ajax({
    		type:"post",
    	    url:"PLATFORM_MAIN/System/delete_file",
    	    data:{'file_url':file_url},
    	    async : true,
    	    dataType:'json',
    	    success:function(data){

    	    	if (data['code']>0) {
					$( "#dialog" ).dialog({
			            buttons: {
			                "确定,#01B044": function() {
			                    $(this).dialog('close');
			                }
			            },
			            contentText:"附件移除成功",
			      		time:1,
			        });
					 	$(even).parent().empty();
				}else{
					$( "#dialog" ).dialog({
			            buttons: {
			                "确定,#e57373": function() {
			                    $(this).dialog('close');
			                }
			            },
			            contentText:data['message'],
			        });
				}
    	    }
 		});
 	} 
  </script>
  
{/block}